package org.ponly.cta4j.drawing.font;

import java.awt.Font;
import java.awt.geom.AffineTransform;

/**
 * TODO .
 *
 * @author vacoor
 * @since 1.0
 */
public class TransformRandomFontFamily extends RandomFontFamily {
    /**
     * twisted.
     */
    private boolean twisted;

    /**
     * sheared.
     */
    private boolean sheared;

    /**
     * TODO doc me.
     */
    public TransformRandomFontFamily() {
    }

    /**
     * TODO doc me.
     *
     * @param twisted twisted
     * @param sheared sheared
     */
    public TransformRandomFontFamily(final boolean twisted, final boolean sheared) {
        this.twisted = twisted;
        this.sheared = sheared;
    }

    /**
     * TODO doc me.
     *
     * @param twisted twisted
     * @param sheared sheared
     * @param fonts   fonts
     */
    public TransformRandomFontFamily(final boolean twisted, final boolean sheared, final Font... fonts) {
        super(fonts);
        this.twisted = twisted;
        this.sheared = sheared;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected Font applyStyle(final Font font) {
        Font styledFont = super.applyStyle(font);

        if (twisted) {
            final AffineTransform at = new AffineTransform();
            final float angle = random.nextFloat() / 3;
            at.rotate(random.nextBoolean() ? angle : -angle);
            styledFont = styledFont.deriveFont(at);
        }

        if (sheared) {
            final double rx = random.nextDouble() / 3;
            final double ry = random.nextDouble() / 3;
            final AffineTransform at = AffineTransform.getShearInstance(rx, ry);
            styledFont = styledFont.deriveFont(at);
        }

        return styledFont;
    }
}
